//
//  MYPopMenu.m
//  奇闻
//
//  Created by 似水灵修 on 14-11-22.
//  Copyright (c) 2014年 MingYueGuCheng. All rights reserved.
//

#import "MYPopMenu.h"

@interface MYPopMenu ()
/**
 *  要显示的控制器View
 */
@property (nonatomic, strong) UIView *contentView;

@end
@implementation MYPopMenu
- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.image = [UIImage resizedImageWithNamed:@"popover_background"];
        self.userInteractionEnabled = YES;
    }
    return self;
}
- (instancetype)initWithContentView:(UIView *)contentView
{
    if (self = [super init]) {
        self.contentView = contentView;
    }
    return self;
}
+ (instancetype)popMenuWithContentView:(UIView *)contentView
{
    return [[self alloc] initWithContentView:contentView];
}
- (void)showInRect:(CGRect)rect
{
    self.frame = rect;
    [self addSubview:self.contentView];
    [MYKeyWindow addSubview:self];
    
}
- (void)dismiss
{
    [self removeFromSuperview];
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    CGFloat x = 0;
    CGFloat y = 9;
    CGFloat w = self.width;
    CGFloat h = self.height - y;
    self.contentView.frame = CGRectMake(x, y, w, h);
}
@end
